﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Resn.WhuPub.BLL
{
        /// <summary>
        /// 实现Type类型的扩展方法
        /// </summary>
        public static class TypeExtension
        {
                /// <summary>
                /// 获取指定类型的智能查询项目的名称集合
                /// </summary>
                /// <param name="type">类型</param>
                /// <returns>
                /// 智能查询项目的名称集合
                /// </returns>
                public static List<String> GetQuertyItems(this Type type)
                {
                        //foreach (var item in type.GetProperties())
                        //{
                        //        QueryAttribute qa = Attribute.GetCustomAttribute(item, typeof(QueryAttribute)) as QueryAttribute;
                        //        if (null != qa)
                        //        {
                        //                result.Add(qa.Name);
                        //        }
                        //}
                        return type.GetProperties().Select(item => Attribute.GetCustomAttribute(item, typeof (QueryAttribute))).OfType<QueryAttribute>().Select(qa => qa.Name).ToList();
                }
        }
}